package com.xinfu.newproject.activity;

import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.CompoundButton;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.xinfu.newproject.R;
import com.xinfu.newproject.adapter.property_provider.PropertyMultipleItemRvAdapter;
import com.xinfu.newproject.base.BaseActivity;
import com.xinfu.newproject.data.DataServer;
import com.xinfu.newproject.entity.MultipleItem;
import com.xinfu.newproject.entity.NormalMultipleEntity;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class PropertyActivity extends BaseActivity implements CompoundButton.OnCheckedChangeListener {

    @BindView(R.id.activity_property_rv)
    RecyclerView mRecyclerView;

    @BindView(R.id.activity_property_all_cb)
    CheckBox allCb;

    private List<NormalMultipleEntity> mData;
    private PropertyMultipleItemRvAdapter propertyMultipleItemRvAdapter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_property);
        ButterKnife.bind(this);
        registerBack();
        setActivityTitle("物业缴费");
        initViewBind();
        initLisener();
    }

    private void initLisener() {
        allCb.setOnCheckedChangeListener(this);
    }

    private void initViewBind() {

        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        mData = DataServer.getPropertyMultipleEntities();
        propertyMultipleItemRvAdapter = new PropertyMultipleItemRvAdapter(mData);

        propertyMultipleItemRvAdapter.setSpanSizeLookup(new BaseQuickAdapter.SpanSizeLookup() {
            @Override
            public int getSpanSize(GridLayoutManager gridLayoutManager, int position) {
                int type = mData.get(position).type;
                if (type == NormalMultipleEntity.TEXT_07) {
                    return MultipleItem.TEXT;
                }
                else if (type == NormalMultipleEntity.TEXT_08) {
                    return MultipleItem.IMG;
                }
                return 0;
            }
        });


        mRecyclerView.setAdapter(propertyMultipleItemRvAdapter);

    }

    @Override
    public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
        if (propertyMultipleItemRvAdapter != null) {
            propertyMultipleItemRvAdapter.addBoolean(b);
        }
    }


}
